﻿Imports System.Windows.Forms
Imports IMDBDLL

Public Class Results
    Private selectedMovie As String
    Private Shared theInstance As Results
    Public Shared Function getInstance() As Results
        If theInstance Is Nothing Then
            theInstance = New Results
        End If
        Return theInstance
    End Function
    Public Property Selected() As String
        Get
            Return selectedMovie
        End Get
        Set(ByVal value As String)
            selectedMovie = value
        End Set
    End Property
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        If ListView1.SelectedIndices.Count = 0 Then
            MessageBox.Show("Please select a movie.")
        Else
            Me.DialogResult = System.Windows.Forms.DialogResult.OK
            Me.Close()
        End If
    End Sub
    Public Sub setResults(ByVal results As List(Of IMDbLink))
        Try
            ListView1.Clear()

            For Each item In results

                Dim newLVi As New ListViewItem
                Dim tt As String

                tt = item.URL
                tt = tt.Remove(0, 7).TrimEnd("/")

                newLVi.Text = tt + "   " + item.Title + " (" + item.Year + ")"
                newLVi.Tag = item.URL

                'If item.Title <> "" Then
                If newLVi.Text <> "" Then

                    ListView1.Items.Add(newLVi)

                End If

            Next

        Catch ex As Exception

        End Try
    End Sub

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
        If ListView1.SelectedIndices.Count > 0 Then
            Selected = ListView1.Items(ListView1.SelectedIndices(0)).Tag
        End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub
End Class
